<?php

namespace App\Services;

use App\Models\Feedback;

class FeedbackService extends BaseService
{
    public $feedbackModel;

    public function __construct()
    {
        $this->feedbackModel = new Feedback();
    }


    /**
     * 2021/3/10--10:31
     * @param int $limit
     * @return array
     * @author:董宗澳
     * @email:2453611300
     * @wechat:DZA74941
     * @QQ:2453611300
     * @web:www.quzha.net
     * @method:getList
     * @effect: 获取反馈列表
     */
    public function getList($limit = 30)
    {
        try {
            $list = $this->feedbackModel->with('feedbackCate')->with('userinfo')
                ->orderBy('is_read', 'desc')->paginate(100)->toArray();
            return $this->success($list);
        } catch (\Exception $e) {
            return $this->error('获取失败');
        }
    }

    /**
     * @param $id
     * @return array
     */
    public function show($id)
    {
        try {
            $data = $this->feedbackModel->with('feedbackCate')->with('userinfo')->where('id', $id)->first()->toArray();
            return $this->success($data, '执行成功');
        } catch (\Exception $e) {
            return $this->error([], '执行失败' . $e->getMessage());
        }
    }


    public function addFeedback($data)
    {
        try {
            $this->feedbackModel->create($data);
            return $this->format([], '反馈成功');
        } catch (\Exception $e) {
            return $this->format_error('反馈失败');
        }
    }

    public function __destruct()
    {
        // TODO: Implement __destruct() method.
    }


}
